package com.zmn.oms.zmn.business.impl.redistribute;

import com.alibaba.fastjson.JSON;
import com.google.api.client.util.Lists;
import com.zmn.base.engineer.common.dro.foreign.engineer.ForeignEngineerDetailInfoDRO;
import com.zmn.base.engineer.dubbo.interfaces.foreign.EngineerListRemoteService;
import com.zmn.base.product.common.consts.BaseProductConsts;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.consts.GlobalConsts;
import com.zmn.manager.redis.lock.DistributedLock;
import com.zmn.manager.redis.lock.DistributedLockUtils;
import com.zmn.oms.business.interfaces.conf.distributereason.ConfOrderDistributeReasonBService;
import com.zmn.oms.common.constant.*;
import com.zmn.oms.common.dto.OrderWorkRedistributeOperator;
import com.zmn.oms.common.enums.RedistributeAuditStatusEnum;
import com.zmn.oms.common.enums.RedistributeStatusEnum;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.model.bo.conf.distribute.reason.ConfOrderDistributeReasonBO;
import com.zmn.oms.model.bo.work.redistribute.OrderWorkRedistributeApplyBO;
import com.zmn.oms.model.bo.work.redistribute.OrderWorkRedistributeAuditBO;
import com.zmn.oms.model.bo.work.redistribute.OrderWorkRedistributeModifyBO;
import com.zmn.oms.model.bo.work.redistribute.RedistributeBO;
import com.zmn.oms.model.dto.order.zmn.ZsNormalUpdateOrderDTO;
import com.zmn.oms.model.dto.product.OrderProductDTO;
import com.zmn.oms.model.dto.work.masterwork.MasterTakeDTO;
import com.zmn.oms.model.dto.work.modify.OrderDistributeDTO;
import com.zmn.oms.model.dto.work.modify.must.OrderDistributeBackDTO;
import com.zmn.oms.model.entity.detail.OrderDetail;
import com.zmn.oms.model.entity.product.OrderProduct;
import com.zmn.oms.model.entity.redistribute.OrderWorkRedistributeApply;
import com.zmn.oms.model.entity.redistribute.OrderWorkRedistributeMaster;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.services.interfaces.detail.OrderDetailService;
import com.zmn.oms.services.interfaces.product.OrderProductService;
import com.zmn.oms.services.interfaces.redistribute.OrderWorkRedistributeApplyService;
import com.zmn.oms.services.interfaces.redistribute.OrderWorkRedistributeMasterService;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import com.zmn.oms.zmn.business.interfaces.redistribute.OrderWorkRedistributeApplyBService;
import com.zmn.oms.zmn.business.interfaces.redistribute.OrderWorkRedistributeAuditBService;
import com.zmn.oms.zmn.business.interfaces.redistribute.OrderWorkRedistributeBService;
import com.zmn.oms.zmn.business.interfaces.redistribute.RedistributeApplyBService;
import com.zmn.oms.zmn.business.interfaces.work.OrderWorkDistributeBackBService;
import com.zmn.oms.zmn.business.interfaces.work.customwork.ZsCustomWorkBService;
import com.zmn.oms.zmn.business.interfaces.work.masterwork.ZsMasterWorkBService;
import com.zmn.oms.zmn.normal.business.interfaces.order.ZsNormalOrderBService;
import com.zmn.track.common.dto.apply.cancel.QueueApplyCancelDataDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 类描述:改派操作业务处理类
 *
 * @author: HuangChao
 * @since: 2022/05/31 10:45
 */
@Slf4j
@Service
public class RedistributeApplyBServiceImpl implements RedistributeApplyBService {

    @Autowired
    private OrderWorkRedistributeApplyBService orderWorkRedistributeApplyBService;
    @Autowired
    private OrderWorkRedistributeAuditBService orderWorkRedistributeAuditBService;
    @Autowired
    private OrderWorkRedistributeBService orderWorkRedistributeBService;
    @Autowired
    private OrderWorkRedistributeApplyService orderWorkRedistributeApplyService;
    @Autowired
    private OrderWorkRedistributeMasterService orderWorkRedistributeMasterService;
    @Autowired
    private OrderWorkDistributeBackBService orderWorkDistributeBackBService;
    @Autowired
    private ConfOrderDistributeReasonBService confOrderDistributeReasonBService;
    @Autowired
    private OrderWorkService orderWorkService;
    @Autowired
    private OrderProductService orderProductService;
    @Autowired
    private OrderDetailService orderDetailService;
    @Resource
    private ZsNormalOrderBService zsNormalOrderBService;
    @Autowired
    private ZsMasterWorkBService zsMasterWorkBService;
    @Autowired
    private ZsCustomWorkBService zsCustomWorkBService;

    @DubboReference(version = com.zmn.base.engineer.common.constants.DubboConsts.INTERFACE_VERSION, check = false)
    private EngineerListRemoteService engineerListRemoteService;

    @Override
    public void redistributeApply(OrderWorkRedistributeApplyBO applyBO) throws OmsBaseException {
        log.debug("保存申请参数：{}", JSON.toJSONString(applyBO));
        // 保存申请
        OrderWorkRedistributeApply orderWorkRedistributeApply = orderWorkRedistributeApplyBService.addOrderWorkRedistributeApply(applyBO);

        // 改派操作
        if (Objects.equals(orderWorkRedistributeApply.getHelpType(), ConfRedistributeConsts.HELP_TYPE_NONE)
                && (Objects.equals(orderWorkRedistributeApply.getAuditType(), ConfRedistributeConsts.AUDIT_TYPE_NONE))) {
            // 如果是地址错误或者品类错误需要先修改订单信息然后再派单
            if (Objects.equals(orderWorkRedistributeApply.getReasonId(), ConfDistributeReasonConsts.REASON_TYPE_CATEGORY_WRONG)
                    || Objects.equals(orderWorkRedistributeApply.getReasonId(), ConfDistributeReasonConsts.REASON_TYPE_ADDRESS_WRONG)) {
                this.updateOrderWorkAddressOrProduct(orderWorkRedistributeApply, 0);
            }

            RedistributeBO redistributeBO = BeanMapper.map(applyBO, RedistributeBO.class);
            redistributeBO.setOrderWorkRedistributeApply(orderWorkRedistributeApply);
            this.redistributeHandle(redistributeBO, orderWorkRedistributeApply.getRedistributeType());
        }
    }

    @Override
    public void autoRedistributeApply(OrderWorkRedistributeApplyBO applyBO) throws OmsBaseException {
        log.info("系统保存申请参数：{}", JSON.toJSONString(applyBO));
        // 1、保存申请
        OrderWorkRedistributeApply orderWorkRedistributeApply = orderWorkRedistributeApplyBService.autoRedistributeApply(applyBO);
        // 2、改派操作
        if (Objects.equals(orderWorkRedistributeApply.getHelpType(), ConfRedistributeConsts.HELP_TYPE_NONE)
                && (Objects.equals(orderWorkRedistributeApply.getAuditType(), ConfRedistributeConsts.AUDIT_TYPE_NONE))) {
            RedistributeBO redistributeBO = BeanMapper.map(applyBO, RedistributeBO.class);
            redistributeBO.setOrderWorkRedistributeApply(orderWorkRedistributeApply);
            this.redistributeHandle(redistributeBO, orderWorkRedistributeApply.getRedistributeType());
        }
    }

    @Override
    public void redistributeAudit(OrderWorkRedistributeAuditBO auditBO) throws OmsBaseException {
        log.info("保存审核参数：{}", JSON.toJSONString(auditBO));
        // 保存审核
        OrderWorkRedistributeApply orderWorkRedistributeApply = orderWorkRedistributeApplyService.selectByKeySrcMaster(auditBO.getRedistributeId());
        orderWorkRedistributeApply = orderWorkRedistributeAuditBService.redistributeAudit(auditBO, orderWorkRedistributeApply);

        // 部分缘由特殊处理
      /*  if (Objects.equals(auditBO.getAuditStatus(), RedistributeAuditStatusEnum.AUDIT_PASS.getCode())
                && (Objects.equals(orderWorkRedistributeApply.getReasonId(), ConfDistributeReasonConsts.REASON_TYPE_CATEGORY_WRONG)
                || Objects.equals(orderWorkRedistributeApply.getReasonId(), ConfDistributeReasonConsts.REASON_TYPE_ADDRESS_WRONG))) {
            // 派单撤回
            try {
                this.distributeBack(auditBO, orderWorkRedistributeApply);
            } catch (OmsBaseException e) {
                log.warn("特殊撤回失败:{}", e.getMessage());
            }

            // 更新工单数据
            this.updateOrderWorkAddressOrProduct(orderWorkRedistributeApply, auditBO.getStreetSource());

            // 发送改派成功消息
            orderWorkRedistributeBService.pushRedistributeResultAppMsg(orderWorkRedistributeApply, null, null, "");
        }*/
        // 录入异常
        if (Objects.equals(auditBO.getSpuriousStatus(), GlobalConsts.YES)) {
            // 虚假改派 保存异常 通知派单总览表 MQ 调整到切面处理
            try {
                orderWorkRedistributeAuditBService.saveSpuriousRedistributeException(auditBO, orderWorkRedistributeApply);
            } catch (OmsBaseException e) {
                log.warn("录入异常失败:{}", e.getMessage());
            }
        }
        // 改派操作
        if (Objects.equals(auditBO.getAuditStatus(), RedistributeAuditStatusEnum.AUDIT_PASS.getCode())) {
            RedistributeBO redistributeBO = BeanMapper.map(auditBO, RedistributeBO.class);
            redistributeBO.setOrderWorkRedistributeApply(orderWorkRedistributeApply);
            this.redistributeHandle(redistributeBO, orderWorkRedistributeApply.getRedistributeType());
        }
    }

    @Override
    public void redistributeTake(OrderWorkRedistributeModifyBO modifyBO) throws OmsBaseException {
        log.info("接受求助参数：{}", JSON.toJSONString(modifyBO));

        // 1、接受求助
        OrderWorkRedistributeApply orderWorkRedistributeApply = orderWorkRedistributeApplyService.selectByOrderIdAndWorkIdAndRedistributeStatusSrcMaster(modifyBO.getOrderId(), modifyBO.getWorkId(), RedistributeStatusEnum.WAIT_REDISTRIBUTE.getCode());
        if (Objects.isNull(orderWorkRedistributeApply)) {
            throw new OmsBaseException(OmsErrorCodeConsts.ERROR_GRAB_ORDER_CODE, "订单已被抢");
        }
        // 2、更新改派申请数据
        OrderWorkRedistributeMaster orderWorkRedistributeMaster = orderWorkRedistributeMasterService.findByRedistributeIdAndMasterId(orderWorkRedistributeApply.getRedistributeId(), modifyBO.getMasterId());
        if (Objects.isNull(orderWorkRedistributeMaster)) {
            throw new OmsBaseException(OmsErrorCodeConsts.ERROR_GRAB_ORDER_CODE, "订单已被抢");
        }
        ResponseDTO<ForeignEngineerDetailInfoDRO> responseDTO = engineerListRemoteService.getEngineerDetailById(modifyBO.getMasterId());
        log.info("redistributeTake#getEngineerDetailById 入参 [{}]  出参 [{}]", modifyBO.getMasterId(), JSON.toJSONString(responseDTO));
        ForeignEngineerDetailInfoDRO baseEngineerDRO = responseDTO.getData();
        if (!responseDTO.isSuccess() || baseEngineerDRO == null) {
            throw new OmsBaseException(OmsErrorCodeConsts.ERROR_ENGINEER_INFO_CODE, "获取工程师信息失败");
        }

        modifyBO.setRedistributeId(orderWorkRedistributeApply.getRedistributeId());
        String lockKey = String.format(LockConsts.LOCK_ORDER_REDISTRIBUTE_HELP_TAKE, modifyBO.getRedistributeId());
        DistributedLock lock = DistributedLockUtils.build(lockKey, LockConsts.LOCK_VALID_TIME);

        if (!lock.tryLock()) {
            throw new OmsBaseException(OmsErrorCodeConsts.ERROR_GRAB_ORDER_CODE, "手慢了，工单已被其他工程师抢走");
        }

        try {
            modifyBO.setDistributeGrid(orderWorkRedistributeMaster.getDistributeGrid());
            orderWorkRedistributeApplyBService.redistributeTake(modifyBO);

            // 如果是地址错误或者品类错误需要先修改订单信息然后再派单
            this.updateOrderWorkAddressOrProduct(orderWorkRedistributeApply, 0);

//            OrderWork orderWork = orderWorkService.findOrderWorkByKey(orderWorkRedistributeApply.getOrderId(), orderWorkRedistributeApply.getWorkId());
            // 改派操作
            // 派单
            OrderDistributeDTO distributeDTO = BeanMapper.map(modifyBO, OrderDistributeDTO.class);
            distributeDTO.setOrderId(orderWorkRedistributeApply.getOrderId());
            distributeDTO.setWorkId(orderWorkRedistributeApply.getWorkId());
            distributeDTO.setMasterId(baseEngineerDRO.getEngineerId());
            distributeDTO.setMasterName(baseEngineerDRO.getRealName());
            distributeDTO.setMasterPhone(baseEngineerDRO.getMobile());
            distributeDTO.setDistributeGrid(orderWorkRedistributeMaster.getDistributeGrid());

            // 设置成已派单
            distributeDTO.setStatus(OrderStatusConsts.WORK_STATUS_DISTRIBUTE);
            // 派单路径
            distributeDTO.setDistributeWay(OrderDistributeConsts.DISTRIBUTE_WAY_PLAT);
            // 派单规则
            distributeDTO.setDistributeRule(OrderDistributeConsts.DISTRIBUTE_RULE_SIMPLE);
            // 派单入口
            distributeDTO.setDistributeEntry(OrderDistributeConsts.DISTRIBUTE_ENTRY_REDISTRIBUTE);

            // 责任人归属
            ConfOrderDistributeReasonBO reason = confOrderDistributeReasonBService.getConfOrderDistributeReasonById(orderWorkRedistributeApply.getReasonId());
            distributeDTO.setLiableType(reason.getLiableType());
            distributeDTO.setDistributeReason(reason.getReason());
            distributeDTO.setDistributeReasonId(reason.getId());
            distributeDTO.setOperateTime(DateUtil.getNow());
            zsCustomWorkBService.saveDistribute(distributeDTO);

            // 领单操作
            MasterTakeDTO masterTakeDTO = BeanMapper.map(modifyBO, MasterTakeDTO.class);
            masterTakeDTO.setOperateTime(DateUtil.addMillisecond(DateUtil.getNow(), 500));
            zsMasterWorkBService.updateMasterTake(masterTakeDTO);

            // 4、通知原工程师改派成功
            orderWorkRedistributeBService.pushRedistributeResultAppMsg(orderWorkRedistributeApply, null, null, "");
        } finally {
            lock.unlock();
        }
    }

    @Override
    public void helpTakeTimeOut(OrderWorkRedistributeModifyBO modifyBO) throws OmsBaseException {
        log.info("领单超时参数：{}", JSON.toJSONString(modifyBO));
        OrderWorkRedistributeApply orderWorkRedistributeApply = orderWorkRedistributeApplyBService.redistributeHelpTimeout(modifyBO);

        // 改派处理 - 这种情况只允许系统改派 配置方面限制
        if (Objects.equals(orderWorkRedistributeApply.getAuditType(), ConfRedistributeConsts.AUDIT_TYPE_NONE)) {
            RedistributeBO redistributeBO = BeanMapper.map(modifyBO, RedistributeBO.class);
            redistributeBO.setRedistributeId(orderWorkRedistributeApply.getRedistributeId());
            redistributeBO.setOperatorId(Long.valueOf(GlobalConsts.OPERATE_USER_TYPE_SYSTEM));
            redistributeBO.setOperator(GlobalConsts.getOperatorTypeName(GlobalConsts.OPERATE_USER_TYPE_SYSTEM));
            redistributeBO.setOperatorType(GlobalConsts.OPERATE_USER_TYPE_SYSTEM);
            orderWorkRedistributeApply.setAddress(null);
            redistributeBO.setOrderWorkRedistributeApply(orderWorkRedistributeApply);
            this.redistributeHandle(redistributeBO, orderWorkRedistributeApply.getRedistributeType());
        }
    }

    @Override
    public void cancelApplyHandle(QueueApplyCancelDataDTO messageDto) {
        try {
            OrderWorkRedistributeOperator orderWorkRedistributeOperator = new OrderWorkRedistributeOperator();
            orderWorkRedistributeOperator.setOrderId(messageDto.getOrderId());
            orderWorkRedistributeOperator.setWorkId(messageDto.getWorkId());
            orderWorkRedistributeOperator.setOperatorId(Long.valueOf(GlobalConsts.OPERATE_USER_TYPE_SYSTEM));
            orderWorkRedistributeOperator.setOperator(GlobalConsts.getOperatorTypeName(GlobalConsts.OPERATE_USER_TYPE_SYSTEM));
            orderWorkRedistributeOperator.setOperatorType(GlobalConsts.OPERATE_USER_TYPE_SYSTEM);
            orderWorkRedistributeOperator.setOperateTime(DateUtil.getNow());
            orderWorkRedistributeOperator.setRedistributeOperatorLogRemark("取消申请发起，系统自动撤销改派申请");
            orderWorkRedistributeApplyBService.autoCancelRedistributeApply(orderWorkRedistributeOperator);
        } catch (OmsBaseException e) {
            log.debug("取消申请发起，系统自动撤销改派申请 失败-{}", e.getMessage());
        }
    }

    /**
     * 改派最终流程处理
     * @param redistributeBO
     * @param redistributeType
     */
    private void redistributeHandle(RedistributeBO redistributeBO,Integer redistributeType) {
        switch (redistributeType) {
            case ConfRedistributeConsts.REDISTRIBUTE_TYPE_SYSTEM:
                orderWorkRedistributeBService.autoRedistribute(redistributeBO);
                break;
            case ConfRedistributeConsts.REDISTRIBUTE_TYPE_SPECIFY:
                orderWorkRedistributeBService.redistribute(redistributeBO);
                break;
            case ConfRedistributeConsts.REDISTRIBUTE_TYPE_REJECT:
                orderWorkRedistributeBService.redistributeReject(redistributeBO);
                break;
            default:
                break;
        }
    }

    /**
     * 派单撤回
     *
     * @param auditBO
     * @param orderWorkRedistributeApply
     * @throws OmsBaseException
     */
    private void distributeBack(OrderWorkRedistributeAuditBO auditBO, OrderWorkRedistributeApply orderWorkRedistributeApply) throws OmsBaseException {
        OrderDistributeBackDTO orderDistributeBackDTO = new OrderDistributeBackDTO();
        orderDistributeBackDTO.setWorkId(orderWorkRedistributeApply.getWorkId());
        orderDistributeBackDTO.setOrderId(orderWorkRedistributeApply.getOrderId());
        orderDistributeBackDTO.setOperatorId(auditBO.getOperatorId());
        orderDistributeBackDTO.setOperatorType(auditBO.getOperatorType());
        orderDistributeBackDTO.setOperator(auditBO.getOperator());
        orderDistributeBackDTO.setStatus(OrderStatusConsts.WORK_STATUS_ASSIGN);
        orderDistributeBackDTO.setResultStatus(OrderStatusConsts.WORK_RESULT_DOING);
        orderDistributeBackDTO.setOperatorRemark(String.format("改派申请审核通过，派单撤回，改派缘由：[%s]", orderWorkRedistributeApply.getReason()));
        orderWorkDistributeBackBService.saveDistributeBack(orderDistributeBackDTO);
    }

    /**
     * 更新工单地址或商品信息
     *
     * @param orderWorkRedistributeApply
     */
    private void updateOrderWorkAddressOrProduct(OrderWorkRedistributeApply orderWorkRedistributeApply, Integer streetSource) {
        try {
            OrderWork dbOrderWork = orderWorkService.findOrderWorkByKeySrcMaster(orderWorkRedistributeApply.getOrderId(), orderWorkRedistributeApply.getWorkId());
            OrderDetail orderDetail = orderDetailService.findOrderDetailByKeySrcMaster(orderWorkRedistributeApply.getOrderId());
            // 判断商品或地址是否修改过
            Boolean isProductChanged = Boolean.FALSE;
            if (NumberUtil.isNotNullOrZero(orderWorkRedistributeApply.getProductId())) {
                if (!Objects.equals(orderWorkRedistributeApply.getProductId(), dbOrderWork.getProductId())) {
                    isProductChanged = Boolean.TRUE;
                }
            }

            Boolean isAddressChanged = Boolean.FALSE;
            if (Objects.nonNull(orderWorkRedistributeApply.getLatitude()) && Objects.nonNull(orderWorkRedistributeApply.getLongitude())) {
                if (!Objects.equals(orderDetail.getLatitude(), orderWorkRedistributeApply.getLatitude()) || !Objects.equals(orderDetail.getLongitude(), orderWorkRedistributeApply.getLongitude())) {
                    isAddressChanged = Boolean.TRUE;
                }

                if (Objects.nonNull(orderWorkRedistributeApply.getAddress()) && !Objects.equals(orderDetail.getAddress(), orderWorkRedistributeApply.getAddress())) {
                    isAddressChanged = Boolean.TRUE;
                }
            }

            if (NumberUtil.isNullOrZero(orderWorkRedistributeApply.getCountyId())) {
                isAddressChanged = Boolean.FALSE;
            }

            // 判断是否需要更新订单相关信息
            if (!isProductChanged && !isAddressChanged) {
                return;
            }

            // 组装更新工单信息参数
            ZsNormalUpdateOrderDTO updateOrderDTO = BeanMapper.map(dbOrderWork, ZsNormalUpdateOrderDTO.class);
            BeanMapper.copy(orderDetail, updateOrderDTO);
            updateOrderDTO.setCityId(dbOrderWork.getCityId());
            updateOrderDTO.setVerifyAssignBack(Boolean.FALSE);
            updateOrderDTO.setVerifyDistributeBack(Boolean.FALSE);
            OrderProduct product = orderProductService.listOrderProductByOrderId(orderWorkRedistributeApply.getOrderId()).get(0);
            if (isProductChanged) {
                List<OrderProductDTO> orderProductList = Lists.newArrayList();
                OrderProductDTO orderProductDTO = new OrderProductDTO();
                orderProductDTO.setProductId(orderWorkRedistributeApply.getProductId());
                orderProductDTO.setProductShowType(BaseProductConsts.ERP_SHOW_TYPE);
                orderProductDTO.setNumber(product.getNumber());
                orderProductDTO.setBrandId(product.getBrandId());
                orderProductList.add(orderProductDTO);
                updateOrderDTO.setOrderProductList(orderProductList);
            } else {
                List<OrderProductDTO> orderProductList = Lists.newArrayList();
                OrderProductDTO orderProductDTO = new OrderProductDTO();
                orderProductDTO.setProductId(product.getProductId());
                orderProductDTO.setShowProductId(product.getShowProductId());
                orderProductDTO.setProductShowType(NumberUtil.isNullOrZero(product.getProductId()) ? BaseProductConsts.EC_SHOW_TYPE : BaseProductConsts.ERP_SHOW_TYPE);
                orderProductDTO.setNumber(product.getNumber());
                orderProductDTO.setBrandId(product.getBrandId());
                orderProductList.add(orderProductDTO);
                updateOrderDTO.setOrderProductList(orderProductList);
            }

            if (isAddressChanged) {
                updateOrderDTO.setLatitude(orderWorkRedistributeApply.getLatitude());
                updateOrderDTO.setLongitude(orderWorkRedistributeApply.getLongitude());
                updateOrderDTO.setStreetId(orderWorkRedistributeApply.getStreetId());
                updateOrderDTO.setStreet(orderWorkRedistributeApply.getStreet());
                updateOrderDTO.setCountyId(orderWorkRedistributeApply.getCountyId());
                updateOrderDTO.setAddress(orderWorkRedistributeApply.getAddress());
                if (NumberUtil.isNotNullOrZero(streetSource)) {
                    updateOrderDTO.setStreetSource(streetSource);
                }
            }

            updateOrderDTO.setOperatorId(orderWorkRedistributeApply.getApplyUserId());
            updateOrderDTO.setOperator(orderWorkRedistributeApply.getApplyUser());
            updateOrderDTO.setOperatorType(orderWorkRedistributeApply.getApplyUserType());
            updateOrderDTO.setOperateTime(DateUtil.getNow());

            // 如果修改订单会导致派单撤回允许派单撤回
            updateOrderDTO.setVerifyDistributeBack(Boolean.TRUE);
            // 设置为不发送到自动流转
            updateOrderDTO.setAutoFlow(Boolean.FALSE);
            // 更新工单
            zsNormalOrderBService.updateOrder(updateOrderDTO);
        } catch (OmsBaseException e) {
            log.error("更新订单数据失败：{}", e);
        }
    }
}